<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Model;


use App\ENUM\ENUM_IS_SHOW;

/**
 * @property int $id
 * @property string $title 标题
 * @property int $type 1文章,2视频,3md
 * @property string $link 文件地址
 * @property int $column_id 栏目id
 * @property string $create_time 创建时间
 * @property int $is_top 是否置顶  0否 1是
 * @property \App\ENUM\ENUM_IS_SHOW $is_show 是否展示  0是 1否
 * @property int $is_delete 是否删除  0否 1是
 */
class Article extends Model
{

    public function getColumn()
    {
        return $this->hasOne(ArticleColumn::class, 'id', 'column_id');
    }

    public function getLabel()
    {
        return $this->belongsToMany(Label::class, 'article_label', 'article_id','label_id','id','id');
    }

    public function getContent()
    {
        return $this->hasOne(ArticleContent::class, 'article_id', 'id');
    }


    /**
     * The table associated with the model.
     */
    protected ?string $table = 'article';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'title', 'type', 'link', 'column_id', 'create_time', 'is_top', 'is_show', 'is_delete'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'type' => 'integer', 'column_id' => 'integer', 'is_show' => ENUM_IS_SHOW::class, 'is_delete' => 'integer', 'is_top' => 'integer'];
}
